package com.dwy2002.room;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dwy2002.common.Result;
import com.dwy2002.common.annotation.RequiresPermission;
import com.dwy2002.enums.Logical;
import com.dwy2002.pojo.dto.rooms.ReserveRoomDTO;
import com.dwy2002.pojo.dto.rooms.RoomsDTO;
import com.dwy2002.pojo.dto.rooms.RoomsPageDTO;
import com.dwy2002.pojo.po.rooms.Rooms;
import com.dwy2002.pojo.vo.rooms.RoomsVO;
import com.dwy2002.room.service.IRoomsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/01/26
 */
@RestController
@RequestMapping("/rooms")
@RequiredArgsConstructor
public class RoomsController {
    private final IRoomsService service;

    /**
     * 分页查询
     * <p>
     * 查询：可按标题搜索
     * <p>
     * 排序：可按课程开始时间、课程创建时间、课程修改时间、课程费用进行升序和降序排序
     * <p>
     * 分类：可按课程状态进行分类。
     *
     * @param roomsPage 包间类的分页数据类
     * @author 杜伟毅
     * @since 2025/1/21 0021 17:32
     */
    @PostMapping("/page")
    public Result<Page<Rooms>> getCoursesPage(@RequestBody RoomsPageDTO roomsPage) {
        return service.getRoomsPage(roomsPage);
    }

    /**
     * 创建包间
     *
     * @param rooms 从前端接收的创建包间信息
     * @author 杜伟毅
     * @since 2025/1/22 0022 18:26
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PostMapping
    public Result<Void> insertRooms(@RequestBody RoomsDTO rooms) {
        return service.insertRooms(rooms);
    }

    /**
     * 批量删除包间
     *
     * @param ids 包间id
     * @author 杜伟毅
     * @since 2025/2/8 0008 0:35
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @DeleteMapping
    public Result<Void> deleteListRooms(@RequestBody List<String> ids) {
        return service.deleteListRooms(ids);
    }

    /**
     * 修改包间
     *
     * @param rooms 前端数据
     * @author 杜伟毅
     * @since 2025/2/8 0008 23:08
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PutMapping
    public Result<Void> updateRooms(@RequestBody RoomsDTO rooms) {
        return service.updateRooms(rooms);
    }

    /**
     * 获取包间详情
     *
     * @param id 包间id
     * @author 杜伟毅
     * @since 2025/2/11 0011 23:21
     */
    @GetMapping("/{id}")
    public Result<RoomsVO> getRoomDetail(@PathVariable String id) {
        return service.getRoomDetail(id);
    }

    /**
     * 预约包间
     *
     * @param reserveRoom 预约包间信息
     * @author 杜伟毅
     * @since 2025/2/12 0012 23:50
     */
    @PostMapping("/reserve")
    public Result<Void> reserveRoom(@RequestBody ReserveRoomDTO reserveRoom) {
        return service.reserveRoom(reserveRoom);
    }

    /**
     * 取消预约包间
     *
     * @param reserveRoom 预约包间信息
     * @author 杜伟毅
     * @since 2025/2/14 0014 21:39
     */
    @PostMapping("/cancel")
    public Result<Void> cancelRoomReserve(@RequestBody ReserveRoomDTO reserveRoom) {
        return service.cancelRoomReserve(reserveRoom);
    }
}
